package main

import (
	"fmt"
)

type User struct {
	name string
	sex  int
	age  int
}

type Student struct {
	User //只在类型，没有名字，相当于继承了User
	id   int
	addr string
}

type Teacher struct {
	*User //只在类型，没有名字，相当于继承了User
	name  string
	addr  string
}

//结构体匿名属性，相当于继承
func main() {
	//顺序初始化
	s0 := Student{User{"tom", 1, 20}, 1, "aaaa"}
	fmt.Println("s0=", s0)
	//指定属性初始化, 没有指定的属性有默认值
	s1 := Student{User: User{"Lucy", 0, 19}}
	fmt.Println("s1=", s1)
	//赋值 部分
	s1.name = "Lily"
	s1.age = 23
	fmt.Println("s1=", s1)
	//赋值 整体
	s1.User = User{"linda", 0, 25}
	fmt.Println("s1=", s1)
	//同时字段遵循就近原则，父类需要显示指定
	t0 := Teacher{&User{}, "lee", "cq"}
	fmt.Println("t0=", t0)

	u0 := new(User) //分配地址
	t1 := Teacher{u0, "wang", "bj"}
	t1.User.name = "zhao"
	t1.sex = 0
	t1.age = 30
	fmt.Println("t1=", *t1.User, t1.name, t1.addr)

}
